package com.siwen.controller;

import com.siwen.api.ApiResult;
import com.siwen.pojo.system.SysUserInformationTbl;
import com.siwen.service.UserService;
import com.siwen.util.ResultUtil;
import org.omg.CORBA.UserException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@CrossOrigin
public class UserController {
    @Resource
private UserService userService;
    /**
     * 查询所有后台系统员工
     * @return
     */
    @RequestMapping("/getSysUser")
    @ResponseBody
    public List<SysUserInformationTbl> selectAll(){
        List<SysUserInformationTbl> sysuser=userService.getsysUserInfo();
        return sysuser;
    }
    @RequestMapping("/login")
    public ApiResult<String> login(HttpSession session, String admincode, String password) {
        SysUserInformationTbl sysUserInformationTbl=null;
        try {
             sysUserInformationTbl=   userService.login(admincode,password);
        } catch (UserException e) {
            e.printStackTrace();
        }

        return ResultUtil.success(sysUserInformationTbl);
    }
    @RequestMapping("/getUser")
    public int insertUser(SysUserInformationTbl sif) {
        SysUserInformationTbl sift = new SysUserInformationTbl();
        sift.setAdmincode("xx123456");
        sift.setAdminname("笑笑");
        sift.setPassword("123123");
        int result=userService.insertUser(sift);
        if (result>0){
            System.out.print("添加成功");
        }else{
            System.out.print("添加失败");
        }
        return result;
    }
}
